package options.view;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import options.controller.OptionTabbedDBListener;
import view.OptionPanelInterface;

public class OptionTabbedDB extends JPanel implements OptionPanelInterface {

	private static final long serialVersionUID = 3798712796209475863L;
	@SuppressWarnings("unused")
	private boolean modified = false;
	private OptionTabbedDBListener listener = null;
	private JComboBox cmbProtocolVersion = null;
	private JTextField txtAddress = null;
	private JTextField txtPort = null;
	private JTextField txtUserName = null;
	private JTextField txtPassword = null;
	private JPanel jPanel = null;
	private JButton buttonSave = null;
	private JButton buttonRestore = null;
	private JLabel lblProtocolVersion = null;
	private JLabel lblAddress = null;
	private JLabel lblPort = null;
	private JLabel lblUserName = null;
	private JLabel lblPassword = null;
	private JPanel jPanelSettings = null;

	/**
	 * This is the default constructor
	 */
	public OptionTabbedDB() {
		super();
		initialize();
		listener = new OptionTabbedDBListener(this);
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setLayout(null);
		this.setVisible(true);
		this.setSize(new java.awt.Dimension(320,290));
		this.add(getJPanel(), null);
	}
	
	public JPanel getJPanel() {
		if(jPanel == null) {
			
			
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new java.awt.Rectangle(0,0,323,290));
			jPanel.add(getJPanelSettings(), null);
			
			jPanel.add(getButtonSalva(), null);
			jPanel.add(getButtonRestore(), null);
			
		}
		
		return jPanel;
	}

	/**
	 * This method initializes txtAddress	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getTxtAddress() {
		if (txtAddress == null) {
			txtAddress = new JTextField();
			
			txtAddress.setBounds(new java.awt.Rectangle(10,90,150,20));
		}
		return txtAddress;
	}

	/**
	 * This method initializes txtPort	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getTxtPort() {
		if (txtPort == null) {
			txtPort = new JTextField();
			txtPort.setBounds(new java.awt.Rectangle(180,90,90,20));
		}
		return txtPort;
	}

	/**
	 * This method initializes txtUserName	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getTxtUserName() {
		if (txtUserName == null) {
			txtUserName = new JTextField();
			txtUserName.setBounds(new java.awt.Rectangle(10,140,150,20));
		}
		return txtUserName;
	}
	
	public JComboBox getCmbProtocolVersion() {
		if (cmbProtocolVersion == null) {
			cmbProtocolVersion = new JComboBox(new String[]{"v1", "v2c", "v3"});
			cmbProtocolVersion.setBounds(new java.awt.Rectangle(10,40,150,20));
		}
		return cmbProtocolVersion;
	}

	/**
	 * This method initializes txtPassword	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	public JTextField getTxtPassword() {
		if (txtPassword == null) {
			txtPassword = new JTextField();
			txtPassword.setBounds(new java.awt.Rectangle(10,190,150,20));
		}
		return txtPassword;
	}
	
	public void setSize(int width, int height) {
		super.setBounds(0, 0, width, height);
		getJPanel().setLocation((width - getJPanel().getWidth())/2, (height - getJPanel().getHeight())/2-10);
	}

	/**
	 * This method initializes buttonSave	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getButtonSalva() {
		if (buttonSave == null) {
			buttonSave = new JButton();
			buttonSave.setText("Salva");
			buttonSave.setBounds(new java.awt.Rectangle(60,250,80,25));
		}
		return buttonSave;
	}

	/**
	 * This method initializes buttonRestore	
	 * 	
	 * @return javax.swing.JButton	
	 */
	public JButton getButtonRestore() {
		if (buttonRestore == null) {
			buttonRestore = new JButton();
			buttonRestore.setText("Ripristina");
			buttonRestore.setBounds(new java.awt.Rectangle(170,250,80,25));
		}
		return buttonRestore;
	}

	/**
	 * This method initializes jPanelSettings	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanelSettings() {
		if (jPanelSettings == null) {
			lblProtocolVersion = new JLabel();
			lblProtocolVersion.setBounds(new java.awt.Rectangle(13,20,100,20));
			lblProtocolVersion.setText("Protocollo SNMP");
			lblAddress = new JLabel();
			lblAddress.setBounds(new java.awt.Rectangle(13,70,100,20));
			lblAddress.setText("Indirizzo IP");
			lblPort = new JLabel();
			lblPort.setBounds(new java.awt.Rectangle(183,70,100,20));
			lblPort.setText("Numero porta");
			lblUserName = new JLabel();
			lblUserName.setBounds(new java.awt.Rectangle(13,120,100,20));
			lblUserName.setText("User Name");
			lblPassword = new JLabel();
			lblPassword.setBounds(new java.awt.Rectangle(13,170,100,20));
			lblPassword.setText("Password");
			
			jPanelSettings = new JPanel();
			jPanelSettings.setLayout(null);
			jPanelSettings.setBounds(new java.awt.Rectangle(5,10,310,230));
			jPanelSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Opzioni di connessione", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
			
			jPanelSettings.add(getCmbProtocolVersion(), null);
			jPanelSettings.add(getTxtAddress(), null);
			jPanelSettings.add(getTxtPort(), null);
			jPanelSettings.add(getTxtUserName(), null);
			jPanelSettings.add(getTxtPassword(), null);
			
			jPanelSettings.add(lblProtocolVersion, null);
			jPanelSettings.add(lblAddress, null);
			jPanelSettings.add(lblPort, null);
			jPanelSettings.add(lblUserName, null);
			jPanelSettings.add(lblPassword, null);
		}
		return jPanelSettings;
	}
	
	public void save() {
		this.listener.save();
	}

	public boolean isModified() {
		return modified;
	}

	public void setModified(boolean value) {
		modified = value;
	}	
}
